Return to doc.sitecore.com

Documentation

Sitecore CMS allows setting up several different sites in a single installation.

Sitecore always works in a certain context site. For example, when a user works in the Sitecore client, the context site is set to “shell”. At the same time, the front-end performs in the context of “website” site.

The clean Sitecore installation contains a number of sites configured by default, which are required for proper system work. The configuration settings are stored in the web.config file. The nature of web applications is such that it is not always convenient or even possible to edit the web.config every time you need to add a new web site. You can refer to the Configuring Multiple Sites article for more information on this subject.

Sitecore provides a possibility to add and configure multiple sites from inside the client without editing the web.config file. The Multiple Sites Manager module puts such possibility into practice. A user can easily manage and add custom sites.

1.  Installation

The Multiple Sites Manager module is distributed as a standard Sitecore package. Thus to start using it, you should install the package. Please refer to the Installing Modules and Packages article if you are not familiar with the standard Sitecore Packager tool.

The module installs a single DLL into the /bin directory and several content items:

The detailed description of each of these items is give below.

Modify the web.config file after the package installation.

Add the following processor into the httpRequestBegin pipeline before the standard SiteResolver processor:

<processor type="Sitecore.Sites.MultiSitesManager, MultiSitesManager" />

Change the “item:added” event:

<event name="item:added">
<handler type="Sitecore.Sites.AddSiteProcessor, MultiSitesManager" method="OnSiteAdded" />
</event>

2.  General Description

2.1.  Site Templates

Three templates under the templates/System/Site templates item are added to the client after the package installation: Site Template, Site Attribute Template and the Site Link Template.

Site Template

Site Template represents the Site configuration information. It contains three sections with fields which match the site attributes of the web.config file:

This template is used to create Site Items which represent separate sites.

Site Link Template

The Site link template inherits from the Standard template and has no own fields. The purpose of the Site link Items is to reference the sites which already exist in the web.config.

Site Attribute Template

Site Attribute Template provides a possibility to add custom attributes to a site definition. For example, it’s possible to add the htmlCacheSize attribute to the ‘website’ site. The item based on this template should be a child under the corresponding Site Item.

The template contains the only field called Value. The name of the Item serves as the attribute name, and the Value field stands for the attribute value.

2.2.  Site Item Folder

All Site Items are located under the system/Sites folder. During the package installation this folder is populated by the Site Link Items.

2.2.1.  Site Link Item

The purpose of the Site link Item is to reference the site which already exists in the web.config. Site Link Items are created automatically once the module is installed. If more sites are added to web.config after the module installation, an administrator will have to create appropriate Site Link Items manually.

The order in which the sites stand under the Sites folder is important for the SiteResolver method. The Sortorder field is used to sort the Sites collection. The default order is the same as in the web.config file.

If the site exists in the web.config file but has no appropriate site link, its order is considered to be zero.

If the site name in web.config is changed, the name of the Site Link Item should be changed manually as well.

2.2.2.  Adding a New Site

Now consider a situation when a custom attribute should be added to the site.

Select a site Item in the content tree, click New and choose New site attribute. Provide a name for this Item – it will become the name of the attribute. Provide a value, e.g. 10MB. Click save - the new attribute is added.

3.  Architectural Notes

All the sites defined in the web.config file populate the global sites collection. The SiteResolver scans this collection upon each URL request and finds the best matching site.

The solution presented here adds custom sites to the global sites collection and sorts it before the SiteResolver interference. An administrator is responsible for providing the sort order of a site. In case the Sort Order is not specified, its value will be considered as zero.

The order in which the sites are sorted in the content tree takes precedence over the site order in the web.config file.

Below is a brief list of the steps required to implement the Multiple Sites solution:

  1. Define a “Site Template” that represents the Site configuration information.
     
  2. Create a set of “Site” items that define the Site configuration information for each site.
     
  3. Create a new project (class library).
     
  4. Create a new class with a Process() method which reads sites from the content tree and adds them into the global sites collection (SiteContextFactory.Sites).
     
  5. Add a new <processor> definition for the newly created class into the <httpRequestBegin> section of the web.config file. The new <processor> definition should be placed before the
    <processor type="Sitecore.Pipelines.HttpRequest.SiteResolver, Sitecore.Kernel" />
    definition.

4.  Troubleshooting

It is recommended to place custom sites after shell and login site link items in the content tree; otherwise, you may experience problems when connecting to Sitecore Shell. If this happens and you cannot enter Sitecore Shell, just go to the web.config and comment out the following processor:

<pipelines>
 <httpRequestBegin>
 <!-- <processor type="Sitecore.Sites.MultiSitesManager, MultiSitesManager" /> -->